package io.renren.modules.haiyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.haiyou.dao.SceneTagDao;
import io.renren.modules.haiyou.entity.SceneTag;
import io.renren.modules.haiyou.service.SceneTagService;
import org.springframework.transaction.annotation.Transactional;


@Service("sceneTagService")
public class SceneTagServiceImpl extends ServiceImpl<SceneTagDao, SceneTag> implements SceneTagService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SceneTag> page = this.page(
                new Query<SceneTag>().getPage(params),
                new QueryWrapper<SceneTag>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SceneTag> findBySceneId(String id) {
        return baseMapper.selectList(new LambdaQueryWrapper<SceneTag>().eq(SceneTag::getSceneId, id));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(SceneTag entity) {
        return SqlHelper.retBool(baseMapper.insert(entity));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(SceneTag entity) {
        return SqlHelper.retBool(baseMapper.updateById(entity));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        if (CollectionUtils.isEmpty(idList)) {
            return false;
        }
        return SqlHelper.retBool(baseMapper.deleteBatchIds(idList));
    }

}